<meta title="商品采集"/>
<div class="p">
    <div class="m-b-md">
        <div class="btn-group">
            <a href="javascript:;" class="btn btn-default btn-sm"
               s-click="S.popupOpen('/collectionSource/collectionSource-add.html').done(function(flag){flag && $collectionSourcesGrid.refresh()})">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a href="javascript:;" class="btn btn-default btn-sm" s-click="setStatus('STARTED')">
                <i class="fa fa-unlock-alt"></i> 启动
            </a>
            <a href="javascript:;" class="btn btn-default btn-sm"
               s-click="setStatus('STOPPED')">
                <i class="fa fa-lock"></i> 停止
            </a>
            <a href="javascript:;" class="btn btn-default btn-sm"
               s-click="setStatus('DELETED')">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <a href="javascript:;" class="btn btn-default btn-sm s-loading-icon " s-click="return $collectionSourcesGrid.refresh()">
            <i class="fa fa-refresh s-loading-spinner"></i>
        </a>
    </div>
    <div id="collectionSourcesGrid"
         s='datac,nda,check'
         s-data="S.get('/api/collectionSource/all')" >
        <table class="table table-striped table-hover table-bordered table-condensed" style="width: 100%;">
            <tr>
                <th style="width: 1px;">
                    <label class="s-checkbox">
                        <input autocomplete="off" type="checkbox" s-check-role="checkall-h"/>
                        <span class="s-checkbox-indicator"></span>
                    </label>
                </th>
                <th>标题</th>
                <th>类型</th>
                <th>关键字</th>
                <th>页数</th>
                <th>启动/停止</th>
                <th>采集开始</th>
                <th>采集结束</th>
                <th>采集时长(s)</th>
                <th>采集状态</th>
                <th>采集信息</th>
                <th>创建时间</th>
                <th>状态</th>
                <th class="text-right">操作</th>
            </tr>
            <tbody s="loop">
            <tr s-loop-role="empty">
                <td colspan="14">
                    <div class="p text-center">
                        未查询到数据
                    </div>
                </td>
            </tr>
            <tr s-loop-role="row" s="datac" s-check-role="i">
                <td>
                    <label class="s-checkbox">
                        <input autocomplete="off" type="checkbox" s-check-role="h"/>
                        <span class="s-checkbox-indicator"></span>
                    </label>
                </td>
                <td name="title"></td>
                <td name="typeTitle"></td>
                <td name="keyword"></td>
                <td>
                    <span name="maxPage"></span>/<span name="pageSize"></span>
                </td>
                <td s="tpl">
                    <span>
                        {%if(this.status=='STARTED'){out.print(this.startTime)}else{out.print(this.stopTime)}%}
                    </span>
                </td>
                <td name="lastCollectStartTime"></td>
                <td name="lastCollectEndTime"></td>
                <td name="collectSeconds"></td>
                <td name="collectStatusTitle"></td>
                <td name="collectMsg"></td>
                <td name="createTime"></td>
                <td s="tpl">
                    {%if(this.status == 'STARTED'){%}
                    <span class="label label-success">{%=this.statusTitle%}</span>
                    {%} else {%}
                    <span class="label label-default">{%=this.statusTitle%}</span>
                    {%}%}
                </td>
                <td class="text-right">
                    <input autocomplete="off" type="button" class="btn btn-xs btn-link" s-click="edit(this)" value="编辑"/>
                    <input autocomplete="off" type="button" class="btn btn-xs btn-link" s-click="collect(this)" value="执行"/>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="14" class="text-right">
                    共有<span name="length"></span>条记录
                </td>
            </tr>
            </tfoot>
        </table>
    </div>
</div>
<script type="text/javascript">
    function setStatus(status) {
        var datas = $collectionSourcesGrid.getCheckedData("id");
        if (datas.length == 0) {
            S.toast("请选择要操作的数据", "warning");
            return;
        }
        S.confirm("确定操作吗？").done(function () {
            S.put("/collectionSource/status/" + status, {ids: datas}).done(function () {
                $collectionSourcesGrid.refresh();
            })
        });
    }
    function edit(s) {
        S.popupOpen("/collectionSource/collectionSource-edit.html", {collectionSource: s.parent().data()}).done(function (rs) {
            rs && $collectionSourcesGrid.refresh();
        });
    }
    function collect(s) {
        S.confirm("确定立即执行吗？").done(function () {
            S.get("/api/collectionSource/collect/" + s.parent().data().id).done(function (rs) {
                rs && S.toast("执行成功");
            })
        });
    }
</script>